package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManageService;
import com.tanhua.result.Result;
import com.tanhua.sso.vo.AdminMovementsVo;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/manage")
public class ManageController {
    @Autowired
    private ManageService manageService;

    //用户数据翻页
    @GetMapping("/users")
    public ResponseEntity selectPage(@RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer pagesize){
        Result result=manageService.selectPage(page,pagesize);
        return ResponseEntity.ok(result);
    }

    /**
     * 根据id查询用户详情
     */
    @GetMapping("/users/{userID}")
    public ResponseEntity findById(@PathVariable("userID") Long userId) {
        return manageService.findById(userId);
    }



    /*视频记录翻页*/
    @GetMapping("/videos")
    public ResponseEntity videos(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pagesize,
                                 Long uid ) {
        Result result = manageService.findAllVideos(page,pagesize,uid);
        return ResponseEntity.ok(result);
    }

    //查看动态列表
    @GetMapping("/messages")
    public ResponseEntity messages(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   Long uid,String state ) {
        Result result = manageService.findAllMovements(page,pagesize,uid,state);
        return ResponseEntity.ok(result);
    }

    //用户冻结
    @PostMapping("/users/freeze")
    public ResponseEntity freeze(@RequestBody Map params) {
        Map map =  manageService.userFreeze(params);
        return ResponseEntity.ok(map);
    }

    //用户解冻
    @PostMapping("/users/unfreeze")
    public ResponseEntity unfreeze(@RequestBody  Map params) {
        Map map =  manageService.userUnfreeze(params);
        return ResponseEntity.ok(map);
    }

    //动态详情
    @GetMapping("messages/{id}")
    public ResponseEntity MessAgesById(@PathVariable("id") String movementId){
        AdminMovementsVo adminMovementsVo=manageService.selectById(movementId);
        return ResponseEntity.ok(adminMovementsVo);
    }

    //评论列表翻页
    @GetMapping("messages/comments")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   String messageID){
       Result result= manageService.comments(page,pagesize,messageID);
       return ResponseEntity.ok(result);
    }

    //审核通过
    @PostMapping("messages/pass")
    public ResponseEntity pass(@RequestBody List<String> items){
        Integer state=1;
        manageService.pass(items,state);
        Map map=new HashMap();
        map.put("message","审核通过");
        return ResponseEntity.ok(map);
    }

    //审核驳回
    @PostMapping("messages/reject")
    public ResponseEntity reject(@RequestBody List<String> items){
        Integer state=2;
        manageService.pass(items,state);
        Map map=new HashMap();
        map.put("message","审核驳回");
        return ResponseEntity.ok(map);
    }

}
